package es.lfp.spain;

import java.util.Scanner;

/**
 * daniel ancin 
 *	class menu
 */
public class App 
{
    public static void main( String[] args )
    {	Scanner reader = new Scanner(System.in);
    	String line = "";
    	int number = 0;
    	String position = "";
    	String name = "";
    	int option = 0;
    	NationalTeam nationalTeam = new NationalTeam();
    	
    	do {
    		option = Menu(reader);
    		switch (option) {
    			case 1:
				addPlayer(reader, nationalTeam);
    				break;
    				
    			case 2:
				deletePlayer(reader, nationalTeam);
    				break;
    			case 3:
				searchByPosition(reader, nationalTeam);
    				break;
    			case 4:
    				System.out.println(nationalTeam.seeAll());
    				break;
    			case 5:
    				System.out.println("Exit");
    				break;
    			default:
    				break;
    		}
    	} while(option!=5);
        System.out.println( "Thanks for using " );
    }
    
    /**
     * search position
     * @param reader
     * @param nationalTeam
     */
	private static void searchByPosition(Scanner reader,
			NationalTeam nationalTeam) {
		String position;
		System.out.println("Insert position:");
		position = reader.nextLine();
		System.out.println("Total in position " + position + ":" + nationalTeam.searchByPos(position).size());
	}
	/**
	 * Delete Player
	 * @param reader
	 * @param nationalTeam
	 */
	private static void deletePlayer(Scanner reader, NationalTeam nationalTeam) {
		String line;
		int number;
		System.out.println("Insert player number:");
		line = reader.nextLine();
		number = Integer.parseInt(line);
		nationalTeam.delPlayer(number);
	}
    
    /**
     * add Player
     * @param reader
     * @param nationalTeam
     */
	private static void addPlayer(Scanner reader, NationalTeam nationalTeam) {
		String line;
		int number;
		String position;
		String name;
		System.out.println("Insert number");
		line = reader.nextLine();
		number = Integer.parseInt(line);
		System.out.println("Insert position");
		position = reader.nextLine();
		System.out.println("Insert name");
		name = reader.nextLine();
		nationalTeam.addPlayer(new Player(number,position,name));
	}
/**
 * menu
 * @param reader
 * @return
 */
	private static int Menu(Scanner reader) {
		String line;
		int option;
		System.out.println("Elige una opción:");
		System.out.println("1) Add player");
		System.out.println("2) Delete player");
		System.out.println("3) Search by position");
		System.out.println("4) See all players");
		System.out.println("5) Exit ");
		line = reader.nextLine();
		option = Integer.parseInt(line);
		return option;
	}
}
